﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using Helpers;
using SilverPOP.Data.Process.DAL;
using SilverPOP.Data.Process.Entity;
using Utilities;


namespace SilverPOP.Data.Process.BLL
{
    public class DataUpdateBLL : BaseBLL
    {
      
      public static List<CampaignEntity> GetActiveCampaings()
      {
          List<CampaignEntity> campaignList = new List<CampaignEntity>();
          List<DataReaderObject> dataList = DAL.DAL.ExecuteStoredProcedureAndGetDataObject("SPR_Get_Active_CampaignIDs");

          if (dataList != null)
          {
              foreach (DataReaderObject dataReader in dataList)
              {
                 campaignList.Add(new CampaignEntity(dataReader.ColumnValueList[1].ToString(),(long)dataReader.ColumnValueList[0]));
              }
          }

          if (campaignList != null && campaignList.Count > 0)
          {
              return campaignList;
          }

          throw new Exception("There is no active campaign found.");
      }


      public static DataTable GetRespondersAndOptOutAndBouncedDataTable(long campaignID, String errorFileNameWithPath)
      {
       
          List<ParamWithValue> spParamValue = new List<ParamWithValue>();
          spParamValue.Add(new ParamWithValue("@campaignId", campaignID));  
          DataTable dataTable = DAL.DAL.ExecuteStoredProcedureWithParametersAndGetDataTable("SPR_SilverPOP_Update", spParamValue);
          return dataTable;
      }


      private static String GetCMSNavigateText(String cmsSectionName)
      {
          return ((ConfigHelpers.CampaignOwnerName != null && ConfigHelpers.CampaignOwnerName == "BARNARD") ? String.Empty : cmsSectionName);
      }


      public static long GetCurrentCampaignActiveSilverPOPDatabaseID(long campaignID)
      {
          List<ParamWithValue> spParamValue = new List<ParamWithValue>();
          spParamValue.Add(new ParamWithValue("@campaignId", campaignID));
          List<DataReaderObject> dataList = DAL.DAL.ExecuteStoredProcedureWithParametersAndGetDataObject("SPR_Get_Active_Campaign_SilverPOP_DatabaseId", spParamValue);

          if (dataList != null)
          {
              foreach (DataReaderObject dataReader in dataList)
              {
                  return (long)dataReader.ColumnValueList[0] > 0 ? (long)dataReader.ColumnValueList[0] : 0;
              }
          }

          return 0;
      }

      public static void MarkedDataInDatabase(long prospectId,String updateType,DateTime updateDate)
      {
          List<ParamWithValue> spParamValue = new List<ParamWithValue>();
          spParamValue.Add(new ParamWithValue("@ProspectId", prospectId));
          spParamValue.Add(new ParamWithValue("@updateType", updateType));
          spParamValue.Add(new ParamWithValue("@updateDate", updateDate));

          bool success = DAL.DAL.UpdateOrDeleteOrInsertDataUsingSP("SPR_Marked_SilverPOP_Contact_Update", spParamValue);

      }
    
    }//end class
}
